package com.itheima.wemedia.controller;


import com.itheima.common.vo.PageResultVo;
import com.itheima.wemedia.dto.WmMaterialPageRequestDto;
import com.itheima.wemedia.pojo.WmMaterial;
import com.itheima.wemedia.service.WmMaterialService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.itheima.core.controller.AbstractCoreController;

import java.util.List;

/**
 * @description <p>自媒体图文素材信息</p>
 *
 * @version 1.0
 * @package com.itheima.wemedia.controller
 */
@Api(value="WmMaterialController",tags = "自媒体图文素材信息")
@RestController
@RequestMapping("/material")
public class WmMaterialController extends AbstractCoreController<WmMaterial> {

    private WmMaterialService wmMaterialService;

    @Autowired
    public WmMaterialController(WmMaterialService wmMaterialService) {
        super(wmMaterialService);
        this.wmMaterialService=wmMaterialService;
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public PageResultVo<WmMaterial> findPage(@RequestBody WmMaterialPageRequestDto dto){
        PageResultVo<WmMaterial> pageResultVo = wmMaterialService.findPage(dto);
        List<WmMaterial> list = (List<WmMaterial>)pageResultVo.getData();
        // 补全图片的全路径, 在这里先写死，后期再改为从配置文件读取
        list.forEach(m->m.setUrl("http://192.168.211.128:8080/" + m.getUrl()));
        return pageResultVo;
    }

}